import { SampleMethodProps } from "@/pages/auditSampling/typing";
import { forwardRef } from "react";
import { leftVerticalDivStyle } from "../NonStatSampleService";
import { CheckBox, NumberBox } from "devextreme-react";
import { consts } from "@/pages/auditSampling/consts";
import { msgError } from "@/utils/msg";
import { getCpasPrimaryColor } from "@/utils/pub";

export const PPSSample = forwardRef((props: SampleMethodProps, ref) => {
    return <>
        <div className="itemBoxDispalyLeft"
            style={{ marginLeft: 0, height: 125, border: '1px solid #e5e5e5', borderRadius: 5, width: '100%' }}  >
            <div style={{ ...leftVerticalDivStyle, paddingTop: 10 }} >
                <div>抽</div>
                <div>样</div>
                <div>条</div>
                <div>件</div>
            </div>
            <div className="" style={{ width: '100%', paddingLeft: 10, paddingTop: 10 }}>

                <div className="itemBoxDispalyLeft" style={{ marginTop: 25, marginLeft: 5 }}>
                    <div style={{ marginTop: 5 }}>抽取数量：</div>
                    <NumberBox
                        style={{ height: 30, width: 100 }}
                        value={props.sampleParameterValues?.ppsSampleParams?.extractNumber}
                        onValueChanged={(e: any) => {
                            props.setSampleParameterValues({
                                ...props.sampleParameterValues,
                                ppsSampleParams: { ...props.sampleParameterValues?.ppsSampleParams, extractNumber: e.value }
                            })
                        }}
                        min={0}
                        showSpinButtons={false}
                        buttons={[{
                            location: 'after',
                            name: 'extractNumber',
                            options: {
                                icon: 'copy',
                                hint: '使用【样本规模】作为抽取数量',
                                onClick: () => {
                                    if (props.sampleParameterValues.measurementSampleSize == 0) {
                                        return msgError('样本规模为0，无法使用！')
                                    }
                                    props.setSampleParameterValues({
                                        ...props.sampleParameterValues,
                                        ppsSampleParams: {
                                            ...props.sampleParameterValues?.ppsSampleParams,
                                            extractNumber: props.sampleParameterValues.measurementSampleSize
                                        }
                                    })
                                }
                            }
                        }]}
                    />
                    <CheckBox
                        style={{ marginLeft: 10 }}
                        text="是否可重现"
                        hint="可重现表示复核时,可以生成同样的样本"
                        value={props.sampleParameterValues?.ppsSampleParams?.useReproducible}
                        onValueChanged={(e: any) => {
                            props.setSampleParameterValues({
                                ...props.sampleParameterValues,
                                ppsSampleParams: { ...props.sampleParameterValues?.ppsSampleParams, useReproducible: e.value }
                            })
                        }}

                    >
                    </CheckBox>
                    <div style={{ marginLeft: 20, marginTop: 5 }}>随机数种子</div>
                    <NumberBox
                        style={{ marginLeft: 10, height: 30, width: 100 }}
                        value={props.sampleParameterValues?.ppsSampleParams?.seed}
                        disabled={!props.sampleParameterValues?.ppsSampleParams?.useReproducible}
                        onValueChanged={(e: any) => {
                            props.setSampleParameterValues({
                                ...props.sampleParameterValues,
                                ppsSampleParams: { ...props.sampleParameterValues?.ppsSampleParams, seed: e.value }
                            })
                        }}
                        min={1}
                        // showSpinButtons={true}
                        buttons={[{
                            location: 'after',
                            name: 'seed',
                            options: {
                                icon: 'pulldown',
                                hint: '重置随机种子',
                                onClick: () => {
                                    props.setSampleParameterValues({
                                        ...props.sampleParameterValues,
                                        ppsSampleParams: {
                                            ...props.sampleParameterValues?.ppsSampleParams,
                                            seed: Math.floor(Math.random() * consts.randomSeed)
                                        }
                                    })
                                }
                            }
                        }]}
                    />
                </div>
                <div style={{ marginTop: 10, color: getCpasPrimaryColor() }}>
                    注: PPS抽样是一种概率抽样方法，其中每个单位被选中的概率与其金额成正比。
                    金额越大的被选中的概率越大，而规模较小的被选中的概率较小。对于关注大额交易或重要项目的场合非常有用。</div>
            </div>
        </div >


    </>
})